home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Prog / Q-R / RANDOM.PAS < prev    next >
Pascal/Delphi Source File  |  1987-05-25  |  2KB  |  64 lines

  1. Program Random;
  2. { Turbo Pascal Random Number Generator.
  3.   Generates a number between 1 and 100. }
  4. { Note: Random is for integer random numbers. Use the SANE function
  5.   RandomX for extended random numbers. }
  6. { Anything that works in MacPascal should work in LightSpeed
  7.   which is basically compiled MacPascal.  Turbo is a Lisa Pascal
  8.   descendent and uses Lisa style calls.  This means that Random returns
  9.   a pseudo-random number from  -32768 to 32767 based on the QD global
  10.   RandSeed which InitGraph sets to 1. If you want a real random number,
  11.   initialize RandSeed using the clock. }
  12.  
  13.  
  14. uses  Memtypes,QuickDraw,OSIntf,ToolIntf;
  15.  
  16. function Randomize (range : integer): integer;
  17. { See Chernicoff V1 p 25 }
  18.  
  19. var 
  20.   rawResult : longint;
  21.  
  22. begin { Randomize }
  23.  
  24.   rawResult := Abs(Random);
  25.   Randomize := (rawResult * range ) div 32768
  26.   
  27.  
  28. end; { Randomize }
  29.  
  30. var
  31.   seconds : longint;
  32.   quit    : char;
  33.   theWindow : WindowPtr;
  34.   WindRect  : rect;
  35.   datahandle  : handle;
  36.  
  37. const
  38.   windTop     = 40;
  39.   windLeft    = 50;
  40.   windBottom  = 320;
  41.   windRight   = 350;
  42.  
  43. begin
  44.   InitGraf(@thePort); { The Mac mantra makes the spirits friendly. }
  45.   InitFonts;
  46.   InitWindows;
  47.   InitMenus;
  48.   TEInit;
  49.   InitDialogs(NIL);
  50.   SetRect(WindRect,windLeft,windTop,
  51.           windRight,windBottom);
  52.   theWindow := NewWindow(NIL,WindRect,'Random Numbers',
  53.                          True,NoGrowDocProc,WindowPtr(-1),
  54.                          True,LongInt(datahandle));
  55.   SetPort(theWindow);
  56.   GetDateTime(seconds);
  57.   RandSeed  := seconds;
  58.   writeLn( 'Type Q to quit' );
  59.   repeat
  60.     WriteLn( Randomize(100));
  61.     read( quit );
  62.   until ( (quit = 'Q') or (quit = 'q') );
  63.  
  64. end. { of program random }